<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: custom_rss_feed.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: peter $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

if(isset($_GET['action']) && $_GET['action'] == 'save_rss')
	$db->db_query("UPDATE ".TABLE_ADMIN_START_PAGE." SET parameter = '".$_POST['custom_rss_url']."' WHERE php_name = 'custom_rss_feed' ");

?>

<form name="custom_rss_feed" action="start.php?subsite=empty&action=save_rss" method="POST">
	<div class="ac"><?php echo TEXT_WIDGET_RSS_URL ?> <input type="text" name="custom_rss_url" value="" /> <input class="button" type="submit" value="<?php echo TEXT_WIDGET_RSS_ENTER ?>" /></div>
</form>

<?php

if(!isset($_POST['custom_rss_url'])) {
	$getFeedURL = $db->db_query("SELECT parameter FROM ".TABLE_ADMIN_START_PAGE." WHERE php_name = 'custom_rss_feed'");
	$url = $getFeedURL->fields['parameter'];

} elseif (isset($_POST['custom_rss_url']) && !empty($_POST['custom_rss_url']))
	$url = $_POST['custom_rss_url'];

require_once(DIR_WS_CLASSES.'rss.minified.php');
$rss = new Rss;

if(!empty($url)) {

	$feed = $rss->getFeed($url, Rss::XML);

	if($feed) {
		echo '<h1 class="rss_header">'.$rss->channel->title.'</h1>';

		foreach($feed as $item){
			echo '<div class="rss_item">';
			echo '<h2><a href="'. $item['link'].'" target="_blank">'. $item['title']. '</a></h2>';
			echo '<span class="rss_item_date">('.$item['date'].')</span>';
			echo '<p>'.$item['description'].'</p>';
			echo '</div>';
		}
	} else
		echo '<div class="rss_item ac">'.TEXT_WIDGET_RSS_ERROR.'</div>';

} else
	echo '<div class="rss_item ac">'.TEXT_WIDGET_RSS_INSERT.'</div>';
?>